from faker import Faker
import sqlite3

# 初始化 Faker 实例，指定中文环境（可选）
fake = Faker('zh_CN')

# 模拟插入一条用户数据
def generate_test_user():
    return {
        'id': fake.random_int(min=10, max=1000),
        'uname': fake.user_name(),
        'upwd': 'e10adc3949ba59abbe56e057f20f883e',  # 假设是 md5("123456")
        'uemail': fake.email(),
        'ushou': fake.name(),
        'uaddress': fake.address(),
        'uyoubian': fake.postcode(),
        'uphone': fake.phone_number()
    }

# 插入到 SQLite 数据库
def insert_test_user(db_path):
    user = generate_test_user()
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    cursor.execute('''
        INSERT INTO df_user_userinfo 
        (id, uname, upwd, uemail, ushou, uaddress, uyoubian, uphone) 
        VALUES (?, ?, ?, ?, ?, ?, ?, ?)
    ''', (
        user['id'], user['uname'], user['upwd'], user['uemail'],
        user['ushou'], user['uaddress'], user['uyoubian'], user['uphone']
    ))
    conn.commit()
    conn.close()
    print(f"已插入测试用户: {user}")

# 调用插入函数
if __name__ == '__main__':
    db_path = r"E:\workspace\自动化测试项目\UI_pytest\电子商城管理系统\daily_fresh_demo-master\db.sqlite3"
    insert_test_user(db_path)
